package fxbattle.client.model;

public enum Direction { 
    NORTH    (0  , -1,  0, -1,  0),
    NORTHEAST(60 , -1,  1,  0,  1),
    SOUTHEAST(120,  0,  1,  1,  1),
    SOUTH    (180,  1,  0,  1,  0),
    SOUTHWEST(240,  0, -1,  1, -1),
    NORTHWEST(300, -1, -1,  0, -1);

    private Direction fOpposite = null;
    private final int fAngle, fEvenColXadj, fEvenColYadj, fOddColXadj, fOddColYadj;
    
    private Direction(int ang, int x, int y){
    	this(ang, x, y, 0, 0);
    }
    
    private Direction(int angle, int iEvenX, int iEvenY, int iOddX, int iOddY){
        fAngle = angle;
        fEvenColXadj = iEvenX;
        fEvenColYadj = iEvenY;
        fOddColXadj = iOddX;
        fOddColYadj = iOddY;
    }

    public int angle(){
        return fAngle;
    }
    
    public Direction opposite(){
        if(fOpposite == null){
            switch (this) {
            case NORTH:
                fOpposite = SOUTH;
                break;
            case NORTHEAST:
                fOpposite = SOUTHWEST;
                break;
            case SOUTHEAST:
                fOpposite = NORTHWEST;
                break;
            case SOUTH:
                fOpposite = NORTH;
                break;
            case SOUTHWEST:
                fOpposite = NORTHEAST;
                break;
            case NORTHWEST:
                fOpposite = SOUTHEAST;
                break;
            default:
                throw new IllegalStateException(this + " was unrecognized.");
            }
        }
        return fOpposite;
    }
    
    public Location goFrom(Location location) {
    	boolean isEvenColumn = location.isEvenColumn();
    	int newX = location.getX() + (isEvenColumn ? fEvenColXadj : fOddColXadj);
    	int newY = location.getY() + (isEvenColumn ? fEvenColYadj : fOddColYadj);
    	return Location.getLocation(newX, newY);
    }
    
    public Direction clockwise(){
    	throw new UnsupportedOperationException("Not implemented yet.");
    }
    
    public Direction counterClockwise(){
    	throw new UnsupportedOperationException("Not implemented yet.");
    }
    
    public static void main(String[] args) {
    	Location loc = Location.getLocation(0, 1);
    	System.out.println("Leaving from " + loc);
    	for(Direction lDir : Direction.values()){
    		System.out.println(lDir + ": " + lDir.goFrom(loc));
    	}
	}

    
}